package com.dwxt.cdms.service;


import com.dwxt.cdms.base.Page;
import com.dwxt.cdms.dao.CallServiceMapper;
import com.dwxt.cdms.entity.CallService;
import com.dwxt.cdms.entity.CallServiceExample;
import com.dwxt.common.base.BaseResult;
import com.dwxt.common.util.PartyUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CallServiceService {

    @Autowired
    private CallServiceMapper callServiceMapper;


    public BaseResult page(Page page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        CallServiceExample example = new CallServiceExample();
        example.setOrderByClause("create_time desc");
        List<CallService> callServiceList = callServiceMapper.selectByExample(example);
        PageInfo pageInfo = new PageInfo(callServiceList);
        return BaseResult.ok(pageInfo);
    }

    public List<CallService> list() {
        CallServiceExample example = new CallServiceExample();
        List<CallService> callServiceList = callServiceMapper.selectByExample(example);
        return callServiceList;
    }

    public BaseResult addOrUpdate(CallService callService) {
        String currentUserId = PartyUtil.getCurrentUserId();
        if (callService.getId() == null) {
            callService.setCreateUser(Integer.valueOf(currentUserId));
            int i = callServiceMapper.insertSelective(callService);
            return BaseResult.ok(i);
        } else {
            callService.setUpdateUser(Integer.valueOf(currentUserId));
            int i = callServiceMapper.updateByPrimaryKeySelective(callService);
            return BaseResult.ok(i);
        }
    }

    public BaseResult delete(Integer id) {
        callServiceMapper.deleteByPrimaryKey(id);
        return BaseResult.ok();
    }

    public CallService selectById(Integer id) {
        return callServiceMapper.selectByPrimaryKey(id);

    }

}
